package com.ruoyi.web.controller.order;

import java.util.HashMap;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson2.JSON;
import com.ruoyi.order.service.IMesDetectNodeService;
import com.ruoyi.order.station.operate.DB5850Value;
import com.ruoyi.order.station.operate.instance.OP07;
import com.ruoyi.websocket.WebSocketUsers;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.order.domain.MesStationOperateFlow;
import com.ruoyi.order.service.IMesStationOperateFlowService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 操作流程Controller
 * 
 * @author guoxl
 * @date 2025-07-06
 */
@RestController
@RequestMapping("/order/operateFlow")
public class MesStationOperateFlowController extends BaseController
{
    @Autowired
    private IMesStationOperateFlowService mesStationOperateFlowService;

    /**
     * 查询操作流程列表
     */
    @PreAuthorize("@ss.hasPermi('order:operateFlow:list')")
    @GetMapping("/list")
    public TableDataInfo list(MesStationOperateFlow mesStationOperateFlow)
    {
        startPage();
        List<MesStationOperateFlow> list = mesStationOperateFlowService.selectMesStationOperateFlowList(mesStationOperateFlow);
        return getDataTable(list);
    }

    /**
     * 导出操作流程列表
     */
    @PreAuthorize("@ss.hasPermi('order:operateFlow:export')")
    @Log(title = "操作流程", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MesStationOperateFlow mesStationOperateFlow)
    {
        List<MesStationOperateFlow> list = mesStationOperateFlowService.selectMesStationOperateFlowList(mesStationOperateFlow);
        ExcelUtil<MesStationOperateFlow> util = new ExcelUtil<MesStationOperateFlow>(MesStationOperateFlow.class);
        util.exportExcel(response, list, "操作流程数据");
    }

    /**
     * 获取操作流程详细信息
     */
    @PreAuthorize("@ss.hasPermi('order:operateFlow:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(mesStationOperateFlowService.selectMesStationOperateFlowById(id));
    }

    /**
     * 新增操作流程
     */
    @PreAuthorize("@ss.hasPermi('order:operateFlow:add')")
    @Log(title = "操作流程", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MesStationOperateFlow mesStationOperateFlow)
    {
        return toAjax(mesStationOperateFlowService.insertMesStationOperateFlow(mesStationOperateFlow));
    }

    /**
     * 修改操作流程
     */
    @PreAuthorize("@ss.hasPermi('order:operateFlow:edit')")
    @Log(title = "操作流程", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MesStationOperateFlow mesStationOperateFlow)
    {
        return toAjax(mesStationOperateFlowService.updateMesStationOperateFlow(mesStationOperateFlow));
    }

    /**
     * 删除操作流程
     */
    @PreAuthorize("@ss.hasPermi('order:operateFlow:remove')")
    @Log(title = "操作流程", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mesStationOperateFlowService.deleteMesStationOperateFlowByIds(ids));
    }

    @GetMapping("/data/{nodeCode}")
    public AjaxResult data(@PathVariable("nodeCode") String nodeCode)
    {
        if (nodeCode == null){
            return AjaxResult.error();
        }
        OP07 op07 = new OP07();
        if (nodeCode.equals("7")){
            op07.setCameraResult01(1);
            op07.setCameraResult02(1);
            op07.setCameraResult03(1);
            op07.setFinalAngleActual01(1.00f);
            op07.setFinalAngleActual02(1.10f);
            op07.setFinalAngleActual03(1.20f);
            op07.setFinalAngleActual04(1.30f);
            op07.setFinalAngleActual05(1.40f);
            op07.setFinalAngleLowLimit01(1.00f);
            op07.setFinalAngleLowLimit02(1.10f);
            op07.setFinalAngleLowLimit03(1.20f);
            op07.setFinalAngleLowLimit04(1.30f);
            op07.setFinalAngleLowLimit05(1.40f);
            op07.setFinalAngleUpLimit01(1.00f);
            op07.setFinalAngleUpLimit02(1.10f);
            op07.setFinalAngleUpLimit03(1.20f);
            op07.setFinalAngleUpLimit04(1.30f);
            op07.setFinalAngleUpLimit05(1.40f);
            op07.setFinalTorqueActual01(1.00f);
            op07.setFinalTorqueActual02(1.10f);
            op07.setFinalTorqueActual03(1.20f);
            op07.setFinalTorqueActual04(1.30f);
            op07.setFinalTorqueActual05(1.40f);
            op07.setFinalTorqueLowLimit01(1.00f);
            op07.setFinalTorqueLowLimit02(1.10f);
            op07.setFinalTorqueLowLimit03(1.20f);
            op07.setFinalTorqueLowLimit04(1.30f);
            op07.setFinalTorqueLowLimit05(1.40f);
            op07.setFinalTorqueUpLimit01(1.00f);
            op07.setFinalTorqueUpLimit02(1.10f);
            op07.setFinalTorqueUpLimit03(1.20f);
            op07.setFinalTorqueUpLimit04(1.30f);
            op07.setFinalTorqueUpLimit05(1.40f);

            op07.setPreAngleActual01(1.00f);
            op07.setPreAngleActual02(1.10f);
            op07.setPreAngleActual03(1.20f);
            op07.setPreAngleActual04(1.30f);
            op07.setPreAngleActual05(1.40f);
            op07.setPreAngleLowLimit01(1.00f);
            op07.setPreAngleLowLimit02(1.10f);
            op07.setPreAngleLowLimit03(1.20f);
            op07.setPreAngleLowLimit04(1.30f);
            op07.setPreAngleLowLimit05(1.40f);
            op07.setPreAngleUpLimit01(1.00f);
            op07.setPreAngleUpLimit02(1.10f);
            op07.setPreAngleUpLimit03(1.20f);
            op07.setPreAngleUpLimit04(1.30f);
            op07.setPreAngleUpLimit05(1.40f);
            op07.setPreTorqueActual01(1.00f);
            op07.setPreTorqueActual02(1.10f);
            op07.setPreTorqueActual03(1.20f);
            op07.setPreTorqueActual04(1.30f);
            op07.setPreTorqueActual05(1.40f);
            op07.setPreTorqueLowLimit01(1.00f);
            op07.setPreTorqueLowLimit02(1.10f);
            op07.setPreTorqueLowLimit03(1.20f);
            op07.setPreTorqueLowLimit04(1.30f);
            op07.setPreTorqueLowLimit05(1.40f);
            op07.setPreTorqueUpLimit01(1.00f);
            op07.setPreTorqueUpLimit02(1.10f);
            op07.setPreTorqueUpLimit03(1.20f);
            op07.setPreTorqueUpLimit04(1.30f);
            op07.setPreTorqueUpLimit05(1.40f);

            op07.setPreResultState01(1);
            op07.setPreResultState02(1);
            op07.setPreResultState03(1);
            op07.setPreResultState04(1);
            op07.setPreResultState05(1);
            op07.setFinalResultState01(1);
            op07.setFinalResultState02(1);
            op07.setFinalResultState03(1);
            op07.setFinalResultState04(1);
            op07.setFinalResultState05(1);

            op07.setPreProgNo01(1);
            op07.setPreProgNo02(1);
            op07.setPreProgNo03(1);
            op07.setPreProgNo04(1);
            op07.setPreProgNo05(1);
            op07.setFinalProgNo01(1);
            op07.setFinalProgNo02(1);
            op07.setFinalProgNo03(1);
            op07.setFinalProgNo04(1);
            op07.setFinalProgNo05(1);


        }
        WebSocketUsers.sendMessageToUserByStationCode(nodeCode, "2|".concat(JSON.toJSONString(op07)));
        return AjaxResult.success();
    }
}
